package com.demo.web.modules.hmi;

import com.demo.common.constant.api.base.IDEntity;
import com.demo.common.constant.api.HmiCatalogAPIConstant;
import com.demo.common.result.ResponseInfo;
import com.demo.common.result.ResultVo;
import com.demo.service.hmi.HmiCatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
@RequestMapping("/hmi/catalog")
public class HmiCatalogController {
    @Autowired
    private HmiCatalogService cataService;

    @GetMapping("/test")
    public String test(){
        return "hello, you are in HmiCatalog test!";
    }

    //******************************************************************
    // 字典分类表
    //******************************************************************
    //查询数据类型列表
    @RequestMapping(value = HmiCatalogAPIConstant.PROPS_DATA_TYPE_API, method = RequestMethod.POST)
    public ResultVo getPropsDataTypeCatalogList(){
        return ResponseInfo.<Object>success(cataService.getPropsDataTypeCatalogList());
    }

    //查询输入表单类型列表
    @RequestMapping(value = HmiCatalogAPIConstant.PROPS_FORM_TYPE_API, method = RequestMethod.POST)
    public ResultVo getPropsFormTypeCatalogList(){
        return ResponseInfo.<Object>success(cataService.getPropsFormTypeCatalogList());
    }

    //查询变量类型
    @RequestMapping(value = HmiCatalogAPIConstant.VAR_TYPE_API, method = RequestMethod.POST)
    public ResultVo getVarTypeList(){
        return ResponseInfo.<Object>success(cataService.getVarTypeCatalogList());
    }

    //查询加密算法类型
    @RequestMapping(value = HmiCatalogAPIConstant.ENCRYPTION_TYPE_API, method = RequestMethod.POST)
    public ResultVo getEncryptionTypeList(){
        return ResponseInfo.<Object>success(cataService.getEncryptionTypeCatalogList());
    }

    //查询通信协议类型
    @RequestMapping(value = HmiCatalogAPIConstant.PROTOCOL_TYPE_API, method = RequestMethod.POST)
    public ResultVo getProtocolTypeList(){
        return ResponseInfo.<Object>success(cataService.getProtocolTypeCatalogList());
    }

    //查询数值单位类型
    @RequestMapping(value = HmiCatalogAPIConstant.UNIT_TYPE_API, method = RequestMethod.POST)
    public ResultVo getUnitTypeList(){
        return ResponseInfo.<Object>success(cataService.getUnitTypeCatalogList());
    }

    //******************************************************************
    // 普通表
    //******************************************************************
    @RequestMapping(value = HmiCatalogAPIConstant.COMPONENT_TYPE_API, method = RequestMethod.POST)
    public ResultVo getComponentTypeCatalogList(){
        return ResponseInfo.<Object>success(cataService.getComponentTypeCatalogList());
    }

    @RequestMapping(value = HmiCatalogAPIConstant.COMPONENT_API, method = RequestMethod.POST)
    public ResultVo getComponentCatalogList(){
        return ResponseInfo.<Object>success(cataService.getComponentCatalogList());
    }

    @RequestMapping(value = HmiCatalogAPIConstant.DEVICE_TYPE_API, method = RequestMethod.POST)
    public ResultVo getDeviceTypeCatalogList(){
        return ResponseInfo.<Object>success(cataService.getDeviceTypeCatalogList());
    }

    @RequestMapping(value = HmiCatalogAPIConstant.DICT_TYPE_API, method = RequestMethod.POST)
    public ResultVo getDictionaryTypeCatalogList(){
        return ResponseInfo.<Object>success(cataService.getDictionaryTypeCatalogList());
    }

    @RequestMapping(value = HmiCatalogAPIConstant.COMPONENT_SEARCH_API, method = RequestMethod.POST)
    public ResultVo getComponentCatalogListByTypeId(@RequestBody IDEntity<Long> idt){
        Long id = idt.getId();
        return ResponseInfo.<Object>success(cataService.getComponentCatalogListByTypeId(id));
    }

}
